//批量调仓截图：/get-more-position-addSub
import http from 'k6/http';
import { check } from 'k6';
import { LOGIN, URL } from './config.js';

// 1. 压测场景：10 个虚拟用户，持续 30 秒
export const options = {
  vus: 10,
  duration: '30s',
};

// 2. 常量
//const BASE = 'https://dev.xiaobeiyangji.com/yangji-api';
const BASE = `${URL}/yangji-api`;

export default function () {
  // 登录 → 拿 accessToken: https://dev.xiaobeiyangji.com/api/login/phone
 const loginRes = http.post(`${BASE}/api/login/phone`,JSON.stringify({
       phone: '15298055260',
       code: '666666',
       clientType: 'PHONE'
     }),
     { headers: { 'Content-Type': 'application/json' } }
   );
  //  https://api.xiaobeiyangji.com/api/get-more-position-addSub
  const payload=JSON.stringify(
 {
    "positionArr":[
        {
        "name":"天弘恒生科技ETF联接C",
        "date":"2025-10-10 14:12:51",
        "state":"success",
        "money":"20.00",
        "type":"buy",
        "code":"012349",
        "moneyNum":20,
        "isSame":false,
        "index":"0"},
        {
            "name":"天弘恒生科技指数C",
            "date":"2025-09-22 14:36:17",
            "state":"success",
            "money":"20.00",
            "type":"buy",
            "isAbnormal":false,
            "code":"012349",
            "moneyNum":20,
            "isSame":false
            ,"index":"1"},
            {
                "name":"天弘恒生科技指数C",
                "date":"2025-09-02 14:28:06",
                "state":"success",
                "money":"300.00",
                "type":"buy",
                "isAbnormal":false,
                "code":"012349",
                "moneyNum":300,
                "isSame":false,
                "index":"2"}],
    "accountId":"c598b9e7-dc3e-418a-93d2-c53c02f1237a",
    "unionId":"o896o5_scUqyJKkRTR1z9Wbm4V98",
    "version":"3.4.0.X"}
  );

  // 简单断言
  check(loginRes, { 'login 200': r => r.status === 200 });

  // 提取 token（返回体在 data.accessToken）
  const token = loginRes.json('data.accessToken');

  // ② 用 token 调 /api/get-version
  const verRes = http.post(`${BASE}/api/get-more-position-addSub`,payload,{ headers: {'Content-Type': 'application/json', Authorization: `Bearer ${token}` } }
  );
  console.log('状态码',verRes.status);
  console.log('返回值',verRes.body);
}